package com.seeyon.apps.kkARPEvent.util;

import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.po.comment.CtpCommentAll;
import com.seeyon.ctp.organization.po.OrgMember;
import com.seeyon.ctp.util.DBAgent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FileUpHelp {
	private static final Log log = LogFactory.getLog(FileUpHelp.class);
	// 新增获取意见方法
	public static String getComment(Long summaryId) throws BusinessException {
		Map map = new HashMap();
		map.put("summaryId", summaryId);
		String queryString = "from CtpCommentAll where moduleId =:summaryId";
		List<CtpCommentAll> comments = DBAgent.find(queryString, map);
		System.out.println(comments.size() + "条意见");
		StringBuffer htmlString = new StringBuffer();
		htmlString.append("<table style=\"text-align:center;width:100%\">");
		htmlString.append("<tr><td><p><strong>发起人附言</strong></p></td></tr><br/>");
		for (CtpCommentAll cta : comments) {
			int ctype = cta.getCtype();
			Date cdateString = cta.getCreateDate();
			SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd");
			String cd = format0.format(cdateString);
			if (ctype == -1) {
				htmlString.append("<tr><td>" + cd + " " + cta.getContent() + "</td></tr>");
			}
		}
		htmlString.append("<tr><td><p><strong>处理区意见 </strong></p></td></tr><br/>");
		for (CtpCommentAll cta : comments) {
			Long createID = cta.getCreateId();
			OrgMember oMember = DBAgent.get(OrgMember.class, createID);
			Date cdateString = cta.getCreateDate();
			SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd");
			String cd = format0.format(cdateString);
			if (cta.getExtAtt1() != null) {
				if (cta.getExtAtt1().equals("collaboration.dealAttitude.agree")) {
					htmlString.append("<tr><td>" + "【同意】" + " " + "<font color='blue'>" + oMember.getName() + "</font>"
							+ " " + cd + " " + cta.getContent() + "</td></tr>");
				}
				else if (cta.getExtAtt1().equals("collaboration.dealAttitude.disagree")) {
					htmlString.append("<tr><td>" + "【不同意】" + " " + "<font color='blue'>" + oMember.getName() + "</font>"
							+ " " + cd + " " + cta.getContent() + "</td></tr>");
				} else if (cta.getExtAtt1().equals("common.node.has.readed.label")) {

					htmlString.append("<tr><td>" + "【已阅】" + " " + "<font color='blue'>" + oMember.getName() + "</font>"
							+ " " + cd + " " + cta.getContent() + "</td></tr>");
				} else {
					htmlString.append("<tr><td></td></tr>");
				}
			}
			htmlString.append("<tr><td>  </td></tr>");
		}
		htmlString.append("</table>");
		return htmlString.toString();
	}
}